@echo off
setlocal enabledelayedexpansion

echo build web_server...
cargo build --release
if %errorlevel% neq 0 (
    echo failed to build web_server
    exit /b %errorlevel%
)

echo build web_site...
set WEB_DIR=web_site
if not exist %WEB_DIR% (
    echo failed: %WEB_DIR% is not exist!
    exit /b 1
)

cd %WEB_DIR%
if %errorlevel% neq 0 (
    echo failed: cannot switch to directory %WEB_DIR%!
    exit /b 1
) else (
    npm run build
    if %errorlevel% neq 0 (
        echo failed: web_site build failed!
        cd ..
        exit /b %errorlevel%
    )
)
cd ..

echo package...
cargo run -p package
if %errorlevel% neq 0 (
    echo failed: package failed!
) else (
    echo failed: package succeeded!
    exit /b %errorlevel%
)+

endlocal
